package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import android.util.Log;
import android.view.View;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityGoodsInfoDetailQuoted3Binding;
import com.sgb.kjwl.di.transport.DaggerTransportComponent;
import com.sgb.kjwl.di.transport.TransportModule;
import com.sgb.kjwl.model.entity.transport.PublicSourceEntity3;
import com.sgb.kjwl.view.widget.GoodsInfoPublicSelectPopWindow3;
import com.sgb.kjwl.viewmodel.transport.GoodsInfoDetailQuotedModel3;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * 找货详情--报价界面
 */
public class GoodsInfoDetailQuotedActivity3 extends AppActivity {

    private String goodsId;
    private ActivityGoodsInfoDetailQuoted3Binding binding;
    private GoodsInfoPublicSelectPopWindow3 pop;

    @Inject
    GoodsInfoDetailQuotedModel3 model;

    public static void start(Context context,String id){
        Intent intent = new Intent(context,GoodsInfoDetailQuotedActivity3.class);
        intent.putExtra("goodsInfoDetailId",id);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerTransportComponent.builder().appComponent(appComponent).transportModule(new TransportModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {

        binding = DataBindingUtil.setContentView(this, R.layout.activity_goods_info_detail_quoted3);
        binding.setViewModel(model);
        binding.include.ivBack.setOnClickListener(this);
        binding.quotedSure.setOnClickListener(this);
        binding.carType.setOnClickListener(this);
        binding.carLength.setOnClickListener(this);

        binding.include.titleView.setText("报价");

        pop = new GoodsInfoPublicSelectPopWindow3(this);
        pop.setBgView(binding.bgPopGrayLayout);
    }

    @Override
    protected void init() {
        goodsId = getIntent().getStringExtra("goodsInfoDetailId");
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()){
            case R.id.iv_back:
                finish();
                break;
            case R.id.quoted_sure:
                //报价
                model.postData();
                break;
            case R.id.car_type:
                List<PublicSourceEntity3> mOptionsItems = new ArrayList<>();
                mOptionsItems.add(new PublicSourceEntity3("平板",1));
                mOptionsItems.add(new PublicSourceEntity3("箱式",2));
                mOptionsItems.add(new PublicSourceEntity3("高栏",3));
                mOptionsItems.add(new PublicSourceEntity3("冷藏",4));
                mOptionsItems.add(new PublicSourceEntity3("冷冻",5));
                pop.setData("选择车型",mOptionsItems);
                pop.setOnResultCallBack(new BasePopWindow.OnResultCallBack() {
                    @Override
                    public void result(Object result) {
                        PublicSourceEntity3 entity = (PublicSourceEntity3)result;
                        binding.carType.setText(entity.getName());
                        model.carType.set(entity.getId());
                        Log.v("select",((PublicSourceEntity3)result).getName());
                    }
                });
                pop.showDownPopwindow(binding.bgPopGrayLayout, true);
                break;
            case R.id.car_length:
                List<PublicSourceEntity3> mOptionsItems1 = new ArrayList<>();
                mOptionsItems1.add(new PublicSourceEntity3("10米",1));
                mOptionsItems1.add(new PublicSourceEntity3("11米",2));
                mOptionsItems1.add(new PublicSourceEntity3("12米",3));
                mOptionsItems1.add(new PublicSourceEntity3("13米",4));
                mOptionsItems1.add(new PublicSourceEntity3("13米",5));
                pop.setData("选择车长",mOptionsItems1);
                pop.setOnResultCallBack(new BasePopWindow.OnResultCallBack() {
                    @Override
                    public void result(Object result) {
                        PublicSourceEntity3 entity = (PublicSourceEntity3)result;
                        binding.carLength.setText(entity.getName());
                        model.carLength.set(entity.getId());
                        Log.v("select",((PublicSourceEntity3)result).getName());
                    }
                });
                pop.showDownPopwindow(binding.bgPopGrayLayout, true);
                break;
        }
    }
}